<?php
//echo get_pelawat_monthly(2007,01,08); exit;
//$a =  $gDateLocale-> GetShortMonth();
//$a=array("8am","9","10","11","12","13","14","15","16",17,18,19,20);

$a =  $gDateLocale-> GetShortMonth();
$datay=array();

if ( !isset($year) || (''==$year) ) $year = Date('Y');

$sql_2 = "select item_id,agency_id,the_date,the_value,date_part('month'::text,the_date) as month from statistics where agency_id='1' and  date_part('year'::text,the_date)='$year' and item_id=$item_id order by month asc";
$res_2 = pg_query($sql_2);
$sum = 0;
while ($dat_2 = pg_fetch_array($res_2)) {
	$k = $dat_2['month'];
	$v = $dat_2['the_value'];
	$hash[$k] = $v;
}

for ($i=1;$i<=12;$i++) {
	$datay[$i-1] = $hash[$i];
}
	//$datay[] = $dat_2['the_value'];



//print_r($a);exit;
// Create the graph. These two calls are always required
$graph = new Graph(650,300,"auto");	
$graph->SetScale("textlin");
$graph->yaxis->scale->SetGrace(20);
$graph->xaxis-> SetTickLabels($a);

// Add a drop shadow
//$graph->SetShadow();

// Adjust the margin a bit to make more room for titles
$graph->img->SetMargin(40,30,20,40);

// Create a bar pot
$bplot = new BarPlot($datay);

// Adjust fill color
$bplot->SetFillColor('orange');
$bplot->SetShadow('#aaaaaa');
$bplot->value->Show();
$bplot->value->SetFont(FF_ARIAL,FS_NORMAL,9);
$bplot->value->SetAngle(0);
$bplot->value->SetFormat('%0.0f');
$graph->Add($bplot);

// Setup the titles
//$graph->title->Set("Statistik Outing Mengikut Bulan bagi Tahun $year");
$graph->title->Set("");
$graph->xaxis->title->Set("Month");
//$graph->yaxis->title->Set("Jumlah Pelajar");
$graph->yaxis->title->Set("1000kW");

$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);

$graph->SetBackgroundGradient('blue:1.9','blue:1.9',GRAD_HOR,BGRAD_MARGIN); 

// Display the graph
$graph->Stroke();
?>
